﻿namespace Harness.Recording
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using mshtml;

    internal static class LocateParser
    {
        #region Constants
        #endregion

        #region Fields

        private static ILocateParseBehavior[] parsers = new ILocateParseBehavior[]
        {
            new LocateParsers.LinkLocateParseBehavior(),
            new LocateParsers.InputButtonLocateParseBehavior(),
            new LocateParsers.ButtonLocateParseBehavior(),
            new LocateParsers.LabelLocateParseBehavior(),
            new LocateParsers.NameLocateParseBehavior(),
            new LocateParsers.CSSLocateParseBehavior(),
        };

        #endregion

        #region Constructors
        #endregion

        #region Destructors
        #endregion

        #region Delegates
        #endregion

        #region Events
        #endregion

        #region Enums
        #endregion

        #region Interfaces

        internal interface ILocateParseBehavior
        {
            string Parse(IHTMLElement element);
        }

        #endregion

        #region Properties
        #endregion

        #region Indexers
        #endregion

        #region Public Methods

        public static string Parse(IHTMLElement element)
        {
            foreach (ILocateParseBehavior parser in parsers)
            {
                string locator = parser.Parse(element);

                if (!string.IsNullOrWhiteSpace(locator))
                {
                    return locator;
                }
            }

            return string.Empty;
        }

        #endregion

        #region Private Methods
        #endregion

        #region Structs
        #endregion

        #region Classes
        #endregion
    }
}
